package com.atguigu.lease.web.admin.schedule;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.entity.LeaseTerm;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author 快点干早点散
 * @Create 2025/4/1 18:51
 * Description:
 */
@Component
public class ScheduledTasks {
    @Autowired
    private LeaseAgreementService leaseAgreementService;
    @Scheduled(cron = "0 0 0 * * * ")
    public  void changeStatus(){

        LambdaUpdateWrapper<LeaseAgreement> leaseAgreementLambdaUpdateWrapper=new LambdaUpdateWrapper<>();
        leaseAgreementLambdaUpdateWrapper.lt(LeaseAgreement::getLeaseEndDate,new Date());
        leaseAgreementLambdaUpdateWrapper.in(LeaseAgreement::getStatus, LeaseStatus.SIGNING,
                LeaseStatus.WITHDRAWING,LeaseStatus.RENEWING);
        leaseAgreementLambdaUpdateWrapper.set(LeaseAgreement::getStatus,LeaseStatus.EXPIRED);
        leaseAgreementService.update(leaseAgreementLambdaUpdateWrapper);
        System.out.println("定时任务检查");


    }
}
